package com.imu.purse.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.imu.purse.interceptor.AuthorizationInterceptor;

/**
 * MVC配置
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2017-04-20 22:30
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter 
{
    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) 
    {
    	List<String> patterns = new ArrayList<String>();
    	patterns.add("/document/**");     	//注册登录相关
    	patterns.add("/api/**");     	  	//接口相关
        registry.addInterceptor(authorizationInterceptor).addPathPatterns(patterns.toArray(new String[patterns.size()]));
    }
    
    public void addCorsMappings(CorsRegistry registry) {
    	registry.addMapping("/**") .allowedOrigins("*") .allowCredentials(true) .allowedMethods("GET", "POST", "DELETE", "PUT","OPTIONS").maxAge(3600); 
    }
}
